using UnityEngine;
using System.Collections;

public class Attack : Animatable {

    public int damage = 1;
    public Vector3 offset; //How do we offset start position from player origin?
    public GameObject attacker; //Character who performed attack

	// Use this for initialization
	void Start () {
	}

    //Can't do this on start since we don't parent right away
    public void PositionAttack()
    {
        transform.parent = attacker.transform;
        transform.localPosition = offset;
        transform.localRotation = Quaternion.identity;
    }

    protected virtual void OnTriggerEnter(Collider other)
    {
        Damagable damagable = other.gameObject.GetComponent<Damagable>();
        if (damagable)
        {
            damagable.DoDamage(damage);
        }
    }

    protected virtual void DestroyAttack()
    {
        if (attacker)
        {
            attacker.GetComponent<Character>().OnAttackComplete();
        }
        Destroy(gameObject);
    }
}
